Skip to content

Conversation

@Rozerxshashank
Copy link

@Rozerxshashank Rozerxshashank commented Dec 18, 2025

πŸ› Bug

The Cancel button in Quick Match could be tapped before the pairing request
was fully created, leading to a null-assertion crash and causing the UI
to get stuck on the loading screen.

βœ… Fix

  • Guarded against null requestDocId
  • Safely closed realtime subscriptions
  • Ensured navigation always occurs via a finally block

πŸ§ͺ Testing

  • Verified logic-level fix for the race condition
  • Cancel action now always exits pairing screen safely
  • Google Sign-In could not be tested locally due to Appwrite OAuth configuration

Fixes #670

Summary by CodeRabbit

  • Bug Fixes
    • Improved request cancellation reliability: safer error handling during cancellation, conditional cleanup to avoid invalid operations, ensured subscriptions are closed reliably, and guaranteed navigation back to the main view after cancellation.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link
Contributor

πŸŽ‰ Welcome @Rozerxshashank!
Thank you for your pull request! Our team will review it soon. πŸ”

  • Please ensure your PR follows the contribution guidelines. βœ…
  • All automated tests should pass before merging. πŸ”„
  • If this PR fixes an issue, link it in the description. πŸ”—

We appreciate your contribution! πŸš€

@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

πŸ“ Walkthrough

Walkthrough

The cancelRequest method in PairChatController was changed to use a try/catch/finally structure: it conditionally deletes the request document only when requestDocId is non-null, resets the ID, awaits subscription closures with error logging, and always navigates to AppRoutes.tabview in the finally block (control-flow and error handling adjusted).

Changes

Cohort / File(s) Summary
Cancel flow refactor
lib/controllers/pair_chat_controller.dart
cancelRequest now uses try/catch/finally; conditional deletion when requestDocId is non-null, requestDocId reset to null, subscriptions awaited/closed with error logging, and navigation to AppRoutes.tabview executed in finally.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped in code to mend the fray,
Caught the faults that went astray,
With try, catch, finallyβ€”steady and keen,
Cancel now exits the loading screen,
A tiny carrot of peace, soft and green. πŸ₯•

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title 'Fix Quick Match cancel button not responding' directly summarizes the main bug fix, matching the primary changeset focus on the cancelRequest method.
Linked Issues check βœ… Passed The code changes implement all requirements from issue #670: guarding null requestDocId, safely closing subscriptions, and ensuring navigation via finally block to fix the unresponsive cancel button.
Out of Scope Changes check βœ… Passed All changes in pair_chat_controller.dart are scoped to fixing the cancelRequest method, directly addressing the race condition and null-assertion crash described in issue #670.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


πŸ“œ Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 6e94b21 and 8e3b730.

πŸ“’ Files selected for processing (1)
  • lib/controllers/pair_chat_controller.dart
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/controllers/pair_chat_controller.dart

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Rozerxshashank
Copy link
Author

Hi @M4dhav πŸ‘‹
I’ve opened a PR that fixes this issue.
Looking forward to your review. Thanks!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/controllers/pair_chat_controller.dart (1)

241-260: Excellent fix for the race condition!

The try/catch/finally structure with null-guarded deletion properly addresses the bug described in issue #670. The finally block ensures navigation always occurs, preventing the stuck UI, and the null check prevents the crash when cancel is tapped before the document is created.

Optional: Move requestDocId = null to the finally block for guaranteed cleanup.

Currently, if document deletion fails (lines 244-248), the exception is caught but requestDocId remains non-null until navigation completes. While Get.offNamedUntil should dispose the controller, moving the reset to finally would be more defensive:

πŸ”Ž View suggested refactor
 Future<void> cancelRequest() async {
   try {
     if (requestDocId != null) {
       await databases.deleteDocument(
         databaseId: masterDatabaseId,
         collectionId: pairRequestCollectionId,
         documentId: requestDocId!,
       );
     }
-
-    requestDocId = null;
-
     await subscription?.close();
     await userAddedSubscription?.close();
   } catch (e) {
     log('Cancel request failed: $e');
   } finally {
+    requestDocId = null;
     Get.offNamedUntil(AppRoutes.tabview, (route) => false);
   }
 }

Optional: Consider independent error handling for subscriptions.

If subscription?.close() throws on line 253, userAddedSubscription?.close() won't execute. Wrapping each in separate try/catch would ensure both closures are attempted:

πŸ”Ž View alternative approach
Future<void> cancelRequest() async {
  try {
    if (requestDocId != null) {
      await databases.deleteDocument(
        databaseId: masterDatabaseId,
        collectionId: pairRequestCollectionId,
        documentId: requestDocId!,
      );
    }
  } catch (e) {
    log('Failed to delete request document: $e');
  }

  try {
    await subscription?.close();
  } catch (e) {
    log('Failed to close subscription: $e');
  }

  try {
    await userAddedSubscription?.close();
  } catch (e) {
    log('Failed to close userAddedSubscription: $e');
  }

  requestDocId = null;
  Get.offNamedUntil(AppRoutes.tabview, (route) => false);
}

This provides more granular error reporting and guarantees all cleanup attempts execute.

πŸ“œ Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b063ecb and 6e94b21.

πŸ“’ Files selected for processing (1)
  • lib/controllers/pair_chat_controller.dart (1 hunks)

@M4dhav M4dhav self-requested a review December 19, 2025 13:30
@M4dhav M4dhav added the bug Something isn't working label Dec 19, 2025
@M4dhav M4dhav changed the base branch from master to dev December 19, 2025 13:31
@M4dhav
Copy link
Contributor

M4dhav commented Dec 19, 2025

Please fix merge conflicts

@M4dhav
Copy link
Contributor

M4dhav commented Dec 19, 2025

For future contributions, please strictly follow the PR Template

@Rozerxshashank
Copy link
Author

Resolved the merge conflict and restored the safe cancelRequest implementation.
The cancel flow now guards against null requestDocId and always navigates back safely.

@Rozerxshashank
Copy link
Author

Hi @M4dhav πŸ‘‹
Just a gentle follow-up on this PR.
I've resolved the merge conflicts and addressed the feedback.
Please let me know if anything else is needed from my side.
Thanks!

@M4dhav
Copy link
Contributor

M4dhav commented Jan 3, 2026

Hey @Rozerxshashank , automated tests are failing

Copy link
Contributor

@M4dhav M4dhav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix tests failure

@Rozerxshashank
Copy link
Author

Hey @M4dhav, I’ve pushed the updated fix for PairChatController.cancelRequest.
Please let me know if any further changes are needed from my side.

@Rozerxshashank Rozerxshashank requested a review from M4dhav January 7, 2026 14:11
);
}

requestDocId = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set the requestDocId to null?

Copy link
Author

@Rozerxshashank Rozerxshashank Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set to null beacuse if app keeps the old requestDocId it may try to cancel the same request again. (Like when button tapped twice)
It just avoids accidental reuse of an invalid ID and reset the controlller to a complete clean state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

@Rozerxshashank Rozerxshashank requested a review from M4dhav January 10, 2026 17:02
Copy link
Contributor

@M4dhav M4dhav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thank you for the contribution.

Could you share a video of the functionality with this fix please?

@M4dhav
Copy link
Contributor

M4dhav commented Jan 10, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2026

βœ… Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cancel button is unresponsive during "Quick Match" loading screen

2 participants